function encodeURI(url: string) {
    try {
        if (url) {
            if (url.includes("?")) {
                let urlObj = new URL(url);
                let path = urlObj.origin + urlObj.pathname;
                let href = url;
                let match = href.match(/\?.*=/g);

                if (match) {
                    let reg = new RegExp("\\" + match[0]);
                    let index = href.search(reg);

                    let key = match[0];
                    let value = href.slice(index + key.length);
                    return path + key + encodeURIComponent(value);
                }
            } else {
                return window.encodeURI(url);
            }
        }

        return url;
    } catch (err) {
        console.log(err);
    }
}

export default encodeURI;
